package com.punai.customer.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.punai.customer.domain.CusMaterialLinkUnit;
import com.punai.customer.mapper.CusMaterialLinkUnitMapper;
import com.punai.customer.service.ICusMaterialLinkUnitService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 材料单位换算Service业务层处理
 *
 * @author zxw
 * @date 2022-12-04
 */
@Service
public class CusMaterialLinkUnitServiceImpl extends ServiceImpl<CusMaterialLinkUnitMapper,CusMaterialLinkUnit> implements ICusMaterialLinkUnitService
{
    @Autowired
    private CusMaterialLinkUnitMapper cusMaterialLinkUnitMapper;

    /**
     * 查询材料单位换算
     *
     * @param id 材料单位换算主键
     * @return 材料单位换算
     */
    @Override
    public CusMaterialLinkUnit selectCusMaterialLinkUnitById(String id)
    {
        return cusMaterialLinkUnitMapper.selectCusMaterialLinkUnitById(id);
    }

    /**
     * 查询材料单位换算列表
     *
     * @param cusMaterialLinkUnit 材料单位换算
     * @return 材料单位换算
     */
    @Override
    public List<CusMaterialLinkUnit> selectCusMaterialLinkUnitList(CusMaterialLinkUnit cusMaterialLinkUnit)
    {
        return cusMaterialLinkUnitMapper.selectCusMaterialLinkUnitList(cusMaterialLinkUnit);
    }

    /**
     * 新增材料单位换算
     *
     * @param cusMaterialLinkUnit 材料单位换算
     * @return 结果
     */
    @Override
    public int insertCusMaterialLinkUnit(CusMaterialLinkUnit cusMaterialLinkUnit)
    {
            return cusMaterialLinkUnitMapper.insert(cusMaterialLinkUnit);
    }

    /**
     * 修改材料单位换算
     *
     * @param cusMaterialLinkUnit 材料单位换算
     * @return 结果
     */
    @Override
    public int updateCusMaterialLinkUnit(CusMaterialLinkUnit cusMaterialLinkUnit)
    {
        return cusMaterialLinkUnitMapper.updateById(cusMaterialLinkUnit);
    }

    /**
     * 批量删除材料单位换算
     *
     * @param ids 需要删除的材料单位换算主键
     * @return 结果
     */
    @Override
    public int deleteCusMaterialLinkUnitByIds(String[] ids)
    {
        return cusMaterialLinkUnitMapper.deleteCusMaterialLinkUnitByIds(ids);
    }

    /**
     * 删除材料单位换算信息
     *
     * @param id 材料单位换算主键
     * @return 结果
     */
    @Override
    public int deleteCusMaterialLinkUnitById(String id)
    {
        return cusMaterialLinkUnitMapper.deleteCusMaterialLinkUnitById(id);
    }

    @Override
    public List<CusMaterialLinkUnit> getMaterialLinkUnitByItemId(String id, Long companyId) {
        LambdaQueryWrapper<CusMaterialLinkUnit> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(CusMaterialLinkUnit::getMaterialId,id);
        wrapper.eq(CusMaterialLinkUnit::getCompanyId,companyId);
        return cusMaterialLinkUnitMapper.selectList(wrapper);
    }

    @Override
    public int setTransition(Long companyId,String materialId, List<CusMaterialLinkUnit> cusMaterialLinkUnitList) {

        cusMaterialLinkUnitMapper.delete(new LambdaQueryWrapper<CusMaterialLinkUnit>().eq(CusMaterialLinkUnit::getCompanyId,companyId).eq(CusMaterialLinkUnit::getMaterialId,materialId));

        this.saveBatch(cusMaterialLinkUnitList);
        return 200;
    }
}
